﻿using System;
using Microsoft.SharePoint;

namespace SPRepository
{
    public class ContentTypeIdFieldType : SimpleFieldType<string>
    {
        public ContentTypeIdFieldType(Guid id) : base(id)
        {
        }

        public override string GetValue(SPListItem item)
        {
            var contentTypeId =  GetFieldRawValue(item);
            var spContentTypeId = (SPContentTypeId) contentTypeId;
            return spContentTypeId.ToString();
        }

        public override void SetValue(SPListItem item, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "The contentTypeId field cannot be null");
            }
            var spContentTypeId = new SPContentTypeId(value);
            item[FieldId] = spContentTypeId;
        }
    }
}